
import cStringIO
import wx


class MiscPanel(wx.Panel):
    def __init__(self, parent):
        self.width = 0
        self.height = 0
        wx.Panel.__init__(self, parent, -1)

    def update(self, data, size, type='picture'):
        stream = cStringIO.StringIO(data)
        img = wx.ImageFromStream(stream)
        self.width = min(size[0] / 3, img.GetWidth())
        if img.GetWidth() == 0:
            self.height = 0
        else:
            self.height = img.GetHeight() * self.width / img.GetWidth()

        img = img.Scale(self.width, self.height)
        wx.StaticBitmap(self, -1, wx.BitmapFromImage(img))

    def getSize(self):
        return self.width, self.height
